package com.taplinker.client.im.rpc;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.text.TextUtils;

import com.taplinker.client.AppConfigContext;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.rpc.command.SimpleBaseCommand;
import com.taplinker.core.rpc.http.HttpTemplate;

public class UploadFilesCmd extends SimpleBaseCommand{
	private List<File> files;
	
	public UploadFilesCmd(List<File> files) {
		this.files = files;
	}

	@Override
	public Result go() {
		List<String> paths = new ArrayList<String>();
		Result result = new Result();
		Result r;
		for(File f : files) {
			r = new HttpTemplate().upload(AppConfigContext.TAPLINKER_WEB + "/services/v2/upload" , f, this);
			if(r == null || TextUtils.isEmpty((String) r.object)) {
				continue;
			}
			paths.add((String) r.object);
		}
		result.object = paths;
		return result;
	}
	
}
